﻿using System;
using System.Collections.Generic;
using SouthernLand.Common.DAL.Articles;

namespace SouthernLand.Common.BOL.Articles
{
    public class Article : BizObject
    {
        #region "---Properties---"

        public int ArticleID { get; set; }

        public string Title { get; set; }

        public string Excerpt { get; set; }

        public string ImageURL { get; set; }

        public int ImageWidth { get; set; }

        public int ImageHeight { get; set; }

        public string Img1 { get; set; }

        public string Img2 { get; set; }

        public string Img3 { get; set; }

        public string Authors { get; set; }

        public string Body { get; set; }

        public DateTime PostDate { get; set; }

        public int TotalViews { get; set; }

        public int Status { get; set; }

        public int Priority { get; set; }

        public int ArticleCateID { get; set; }

        public string Username { get; set; }

        #endregion

        public static string GetImageHot(int articleId)
        {
            try
            {
                Article obj = GetArticleByArticleID(articleId);
                if (obj.Priority == 1)
                    return "<img src=" + Globals.ImagesUrl() + "hot.gif>";
                return "";
            }
            catch
            {
                return "";
            }
        }

        public static List<Article> NhieuNguoiQuanTam()
        {
            var db = new ArticleDAL();
            return db.NhieuNguoiQuanTam();
        }

        public static List<Article> GetTopOnBanner()
        {
            var db = new ArticleDAL();
            return db.GetTopOnBanner();
        }

        public static List<Article> GetArticleMenu(int ArticleCateID)
        {
            var db = new ArticleDAL();
            return db.GetArticleMenu(ArticleCateID);
        }

        public static List<Article> GetTuVan(int CateID)
        {
            var db = new ArticleDAL();
            return db.GetTuVan(CateID);
        }

        //Get GetArticleByParentID
        public static List<Article> GetArticleByParentID(int ParentID)
        {
            var db = new ArticleDAL();
            return db.GetArticleByParentID(ParentID);
        }

        public static List<Article> GetArticleRecent(Int32 ArticleCateID)
        {
            var db = new ArticleDAL();
            return db.GetArticleRecent(ArticleCateID);
        }

        public static List<Article> GetArticleHomePage(int ArticleCateID)
        {
            var db = new ArticleDAL();
            return db.GetArticleHomePage(ArticleCateID);
        }

        public static List<Article> GetArticleHomeByParentID(int ParentID)
        {
            var db = new ArticleDAL();
            return db.GetArticleHomeByParentArticleCateID(ParentID);
        }

        public static List<Article> Search(int CateID, string Keyword, string Sort, int PageIndex, int PageSize)
        {
            var db = new ArticleDAL();
            return db.Search(CateID, Keyword.Trim(), Sort, PageIndex, PageSize);
        }

        public static int SearchCount(int CateID, string Keyword)
        {
            var db = new ArticleDAL();
            return db.SearchCount(CateID, Keyword.Trim());
        }

        public static List<Article> Search(string Keyword, int CateID)
        {
            var db = new ArticleDAL();
            if (Keyword.Trim() != "")
                return db.Search(Keyword.Trim(), CateID);
            else
                return db.GetArticleByParentID(CateID);
        }

        //Get All Article
        public static List<Article> GetAllArticle()
        {
            var db = new ArticleDAL();
            return db.GetAllArticle(1, MAXROWS);
        }

        //Get All Article
        public static List<Article> GetAllArticle(int PageIndex, int PageSize)
        {
            var db = new ArticleDAL();
            return db.GetAllArticle(PageIndex, PageSize);
        }

        // Get Count All records of Table  Article
        public static int GetCountArticle()
        {
            var db = new ArticleDAL();
            return db.GetCountArticle();
        }

        public static string GetImageURLByArticleID(int ArticleID)
        {
            var db = new ArticleDAL();
            return db.GetImageURLByArticleID(ArticleID);
        }

        public static int GetArticleCateIDByArticleID(int ArticleID)
        {
            var db = new ArticleDAL();
            return db.GetArticleCateIDByArticleID(ArticleID);
        }

        public static List<Article> GetTop2ArticleByArticleCateID(int ArticleCateID)
        {
            var db = new ArticleDAL();
            return db.GetTop2ArticleByArticleCateID(ArticleCateID);
        }

        public static List<Article> GetTop10ArticleByArticleCateID(int ArticleCateID)
        {
            var db = new ArticleDAL();
            return db.GetTop10ArticleByArticleCateID(ArticleCateID);
        }

        // lay thong tin theo loai tin
        public static List<Article> GetArticleByArticleCateID(int ArticleCateID)
        {
            var db = new ArticleDAL();
            return db.GetArticleByArticleCateID(ArticleCateID);
        }

        public static Article GetArticleByArticleID(int ArticleID)
        {
            var db = new ArticleDAL();
            return db.GetArticleByArticleID(ArticleID);
        }

        //Lay nhung tin tuc nhieu nguoi xem nhat de hien thi tren menu
        public static List<Article> GetArticleTopTotalviews(int ArticleCateID)
        {
            var db = new ArticleDAL();
            return db.GetArticleTopTotalviews(ArticleCateID);
        }

        //lay cac thong bao khac thong bao hien tai
        public static List<Article> GetArticleOtherArticleID(int ArticleID, int ArticleCateID)
        {
            var db = new ArticleDAL();
            return db.GetArticleOtherArticleID(ArticleID, ArticleCateID);
        }

        public static int Insert(Article obj)
        {
            var db = new ArticleDAL();
            return db.Insert(obj);
        }

        public static int Update(Article obj)
        {
            var db = new ArticleDAL();
            return db.Update(obj);
        }

        public static int UpdateTotalViews(int ArticleID)
        {
            var db = new ArticleDAL();
            return db.UpdateTotalViews(ArticleID);
        }

        public static int Delete(int ArticleID)
        {
            // xoa hinh truoc
            FileProcess.DeleteFile(Globals.PhysicalApplicationPath() + "UserUpload/Articles/" +
                                   GetImageURLByArticleID(ArticleID));
            var db = new ArticleDAL();
            return db.Delete(ArticleID);
        }
    }
}